/*
 * 描述
 * Created by: litangyu
 * 包含类名列表
 * 版本信息，版本号 v1.0
 * 创建日期 16/8/30
 * 版权声明
*/
package com.foton.logistic.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.foton.logistic.R;
import com.foton.logistic.base.BaseActivity;
import com.foton.logistic.model.user.UserModelEntity;
import com.foton.logistic.util.SharedUtil;
import com.foton.logistic.util.tool.StringUtil;

import java.io.Serializable;

import butterknife.InjectView;

/**
 * 描述
 * 个人信息
 * Created by: litangyu<br/>
 * Created on: 16/8/30 上午10:27
 */
public class PersonalInfoActivity extends BaseActivity {

    @InjectView(R.id.ft_ui_tv_username)
    public TextView name;
    @InjectView(R.id.ft_ui_tv_sex)
    public TextView sex;
    @InjectView(R.id.ft_ui_tv_id)
    public TextView driverId;
    @InjectView(R.id.ft_ui_tv_mobile)
    public TextView phone;
    @InjectView(R.id.ft_ui_tv_driver_id)
    public TextView driverNo;
    @InjectView(R.id.ft_ui_tv_server)
    public TextView carrier;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
            finish();
            return;
        }
        setTaskTag(getClass().getSimpleName());
        setContentView(R.layout.ft_ui_personal_info);
    }

    @Override
    public void init() {
        setBackLayoutVisibility(View.VISIBLE);
        setTitleText(getString(R.string.personal_info));
        setTitleTextVisibility(View.VISIBLE);

        UserModelEntity userInfo = SharedUtil.getUserInfo(this);
        if (null != userInfo) {
            name.setText(userInfo.getDriverName() == null ? "" : userInfo.getDriverName());
            sex.setText(userInfo.getSex() == 0 ? getString(R.string.man) : getString(R.string
                    .woman));
            carrier.setText(userInfo.getCarrier() == null ? "" : userInfo.getCarrier());

            String driverId = userInfo.getDriverIdcard() == null ? "" : userInfo.getDriverIdcard();
            String driverNo = userInfo.getDriverNo() == null ? "" : userInfo.getDriverNo();
            String phone = userInfo.getDriverPhone() == null ? "" : userInfo.getDriverPhone();

            this.phone.setText(phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", getString(R.string.mobile_hide_regex)));

            StringBuilder sb;
            if (!StringUtil.isEmpty(userInfo.getDriverIdcard())) {
                sb = new StringBuilder();
                if (driverId.length() <= 7) {
                    this.driverId.setText(driverId);
                } else {
                    String start = driverId.substring(0, 3);
                    String end = driverId.substring(driverId.length() - 4, driverId.length());
                    sb.append(start);
                    sb.append(getString(R.string.hide_sign));
                    sb.append(end);
                    this.driverId.setText(sb.toString());
                }
            }

            if (!StringUtil.isEmpty(userInfo.getDriverNo())) {
                sb = new StringBuilder();
                if (driverNo.length() <= 7) {
                    this.driverNo.setText(driverNo);
                } else {
                    String start = driverNo.substring(0, 3);
                    String end = driverNo.substring(driverNo.length() - 4, driverNo.length());
                    sb.append(start);
                    sb.append(getString(R.string.hide_sign));
                    sb.append(end);
                    this.driverNo.setText(sb.toString());
                }
            }
        }
    }
}
